package com.steellee.leeexcel.dto;

import com.alibaba.excel.metadata.data.DataFormatData;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

/**
 * 内部类自定义单元格样式
 */
public class MetaCellStyle extends WriteCellStyle {
    //指定字体样式
    protected MetaCellFont cellFont;
    //自定义背景色
    protected String hexadecimalCode;

    public void setHexadecimalCode(String hexadecimalCode) {
        int r = Integer.valueOf(hexadecimalCode.substring(1, 3), 16);
        int g = Integer.valueOf(hexadecimalCode.substring(3, 5), 16);
        int b = Integer.valueOf(hexadecimalCode.substring(5, 7), 16);
        HSSFColor color = new HSSFWorkbook().getCustomPalette().findSimilarColor(r, g, b);
        this.setFillForegroundColor(color.getIndex());
    }

    public MetaCellStyle() {
        super();
    }

    @Override
    public DataFormatData getDataFormatData() {
        return super.getDataFormatData();
    }

    public void setCellFont(MetaCellFont cellFont) {
        this.setWriteFont(cellFont);
    }

    @Override
    public WriteFont getWriteFont() {
        return cellFont;
    }
}